import {request} from "../../request/index.js"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    array1: ["10kv","20kv","30kv"],
    value1: 0,
    value2: 0,
    value3: 0,
    value4: 0,
    disable: false,
    wire_voltLevel:'',
    wareHose:'',
    healthStatus:'',
    wireName:'',
    tagID:'',
    manufacturer:'',
    array2:["1号仓库","2号仓库"],
    array3:["健康","故障","停运"],
    array4:["1号厂家","2号厂家"],
    date: null,
  },
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
    console.log(this.data.date)
  },
  bindChange: function (e) {
    this.setData({
      value1: e.detail.value
    })
    this.setData({
      wire_voltLevel: this.data.array1[e.detail.value]
    })
  },
  bindChange1:function(e){
    this.setData({
      value2: e.detail.value
    })
    this.setData({
      wareHose: this.data.array2[e.detail.value]
    })
  },
  bindChange3:function(e){
    this.setData({
      value3: e.detail.value
    })
    this.setData({
      healthStatus: this.data.array3[e.detail.value]
    })
  },
  bindChange4:function(e){
    this.setData({
      value4: e.detail.value
    })
    this.setData({
      healthStatus: this.data.array3[e.detail.value]
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    console.log(options)
    var wire=JSON.parse(options.wire)
    console.log(wire)

    that.setData({
      wire_voltLevel:wire.wire_voltLevel,
      wareHose:wire.wareHouse,
      healthStatus:wire.healthStatus,
      manufacturer:wire.manufacturer,
      wireName:wire.wireName,
      tagID:wire.tagID
    })


    request({
        url: "/wire/dateChange", 
        data: {
          nowDate:(new Date()).toLocaleDateString()
        }, 
        header: {
          'content-type': 'application/json' // 默认值
        }
      })
      .then(res => {
    that.setData({
      date: res.data
    })
  })
  },

  formSubmit: function (e) {
    console.log(e)
    request({
      url: "/wire/addWire", 
      data: {
        wireName:e.detail.value.wireName,
        wire_voltLevel: this.data.wire_voltLevel,
        wareHouse: this.data.wareHose,
        healthStatus: this.data.healthStatus,
        manufacturer: this.data.manufacturer,
        tagID:this.data.tagID,
        date:this.data.date
      }, 
      header: {
        'content-type': 'application/json' // 默认值
      }
    })
    .then(res => {
      if (res.statusCode == 200) {
        wx.showToast({
          title: '正在跳转',
          icon: 'success',
          duration: 2000
        })
        setTimeout(function () {
          wx.navigateTo({
            url: '../qrcode/qrcode?pointID='+res.data.wireCode,
          })
        }, 2000)
      } else {
        wx.showToast({
          title: res.data.message,
          icon: 'none',
          duration: 2000
        })
      }
    })
  }
})